﻿#ifndef HELPER_HTTPHELPER_H_
#define HELPER_HTTPHELPER_H_

// Qt lib import
#include <QObject>
#include <QDebug>
#include <QTimer>

// Project lib import
#include "wthttp.h"

#define MIN_LOAD_TIME_SPACE 2000 //加载数据的最小时间间隔

class IMHttpRequest: public WTHttpRequest
{
    Q_OBJECT
    Q_PROPERTY( bool noReplyCode READ noReplyCode WRITE setNoReplyCode NOTIFY noReplyCodeChanged )

public:
    void setHeader(const QString& key,const QString& value);

private:
    bool requestHeaderProvider(
        QNetworkRequest &request ) override;

    bool requestUrlSplicer(
        QNetworkRequest &request ) override;

    bool requestDataSerializer(
        QByteArray &data ) override;

    bool responseDataParser(
        const QPointer< QNetworkReply > &reply,
        const QByteArray &               sourceData,
        QVariant &                       targetData,
        QString &                        message ,int & code ) override;

    // Property statement code start


private: bool noReplyCode_ = false;
public: inline bool noReplyCode() const;
public: inline void setNoReplyCode(const bool &newValue);
    Q_SIGNAL void noReplyCodeChanged(const bool noReplyCode);

   inline bool enableOriginData() const;
   inline void setEnableOriginData(bool newEnableOriginData);

signals:
    void enableOriginDataChanged();

private:
    QMap<QString,QString> header_;

    bool m_enableOriginData=false;
    // Property statement code end
    Q_PROPERTY(bool enableOriginData READ enableOriginData WRITE setEnableOriginData NOTIFY enableOriginDataChanged)
};

class HttpHelper: public QObject
{
    Q_OBJECT
    Q_DISABLE_COPY( HttpHelper )

private:
    HttpHelper();

    virtual ~HttpHelper() override;

public:
    static HttpHelper *instance();

    bool init();
public slots:
    QObject *createIMRequest();
private:

};

// .inc include
#include "httphelper.inc"

#endif//HELPER_HTTPHELPER_H_
